home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Graphics / MapMaker / Source / OutputView.m < prev    next >
Text File  |  1990-12-04  |  5KB  |  227 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import "OutputView.h"
  5. #import <appkit/appkit.h>
  6. #import "constants.h"
  7. #import <math.h>
  8. #import "ControlObject.h"
  9.  
  10. id parser;
  11.  
  12. void outputPoints(PointList *p)
  13. {
  14.     int s;
  15.     Point *pt;
  16.     
  17.     for(s=gotoPointInList(p,0,&pt);s;s=gotoNextPointInList(p,&pt)) {
  18.         ("x : %f   |y: %f   |pen: %d   |colour: %f\n",pt->x,pt->y,pt->pen,pt->pencolour);
  19.     }
  20. }
  21.  
  22. DPSTimedEntryProc handlerfunction(DPSTimedEntry te,double now,void *userdata)
  23. {
  24.     [parser doEntry];
  25. }
  26.  
  27. void doMapping(PointList *p)
  28. {
  29.     int t;
  30.     Point *pt;
  31.     int lastpen = UP;
  32.     float lastcol = NX_LTGRAY;
  33.  
  34.     PSsetgray(NX_LTGRAY);
  35.     PSsetlinewidth(0.0);
  36.     for(t=gotoPointInList(p,0,&pt);(t);t=gotoNextPointInList(p,&pt)) {
  37.         if (lastpen == DOWN)
  38.             PSlineto(pt->x,pt->y);
  39.         else
  40.             PSmoveto(pt->x,pt->y);
  41.         if (lastcol != pt->pencolour) {
  42.             PSstroke();
  43.             PSnewpath();
  44.             PSmoveto(pt->x,pt->y);
  45.             PSsetgray(pt->pencolour);
  46.             lastcol = pt->pencolour;
  47.         }
  48.         lastpen = pt->pen;
  49.     }
  50.     PSstroke();
  51. }
  52.  
  53. @implementation OutputView
  54.  
  55. - setItUp:sender
  56. {
  57.     int i;
  58.     NXRect r;
  59.  
  60.     [self setDrawSize:(ORight-OLeft) :(OTop-OBottom)];
  61.     [self setDrawOrigin:OLeft :OBottom];
  62.     animating = STOPPED;
  63.     currentFrame = 0;
  64.     parser = self;
  65.     stepValue = 0.0;
  66.     maxFrame = 0;
  67.     
  68.  
  69.     alertWindow = [sender alertWindow];
  70.     alertText = [sender alertText];
  71.     return self;
  72. }
  73.  
  74. - (BOOL)gridState
  75. {
  76.     return GridOn;
  77. }
  78.  
  79. - setGridState:(BOOL)newGridState
  80. {
  81.     oldGridOn = GridOn;
  82.     GridOn = newGridState;
  83.     return self;
  84. }
  85.  
  86.  
  87. - drawSelf:(const NXRect *)rects :(int)rectCount
  88. {
  89.     Point *pt;
  90.     int s;
  91.     if (animating) {
  92.         currentFrame= currentFrame + animating;
  93.         if (currentFrame >= maxFrame)
  94.             currentFrame = 0;
  95.         else if (currentFrame < 0)
  96.             currentFrame = (maxFrame-1);
  97.         [outputFrames[currentFrame] composite:NX_COPY toPoint:&(bounds.origin)];
  98.     } else {
  99.         NXEraseRect(&bounds); 
  100.         doMapping(&stillPoints);
  101.         }
  102.     return self;
  103. }    
  104.  
  105. - doStill:(ProjParam *)params :(PointList *)pts
  106. {
  107.     newPointList(&stillPoints);
  108.     convertPoints(pts,&stillPoints,GridOn,params);
  109.     [self display];
  110.     freePointList(&stillPoints);
  111.     return self;
  112. }
  113.  
  114. - doEntry
  115. {
  116.     [self display];
  117.     return self;
  118. }
  119.  
  120. - setupAnimation:(ProjParam *)params :(float)step :(PointList *)pts :(int)force
  121. {
  122.     int i;
  123.     float g,h,l;
  124.     PointList outputPoints;
  125.     char outstr[100];
  126.     
  127.     if ((!force) && (step == stepValue) && (params->phi1 == currentParams.phi1)
  128.                      && (params->proj == currentParams.proj) && (params->radius == currentParams.radius)
  129.                      && (oldGridOn == GridOn))
  130.      {
  131.          g = ((params->lon0*180)/PI);
  132.         h = ((currentParams.lon0*180)/PI);
  133.         l = (h-g)/step;
  134.         if ((l > (round(l)-0.001)) && (l < (round(l)+0.001))){
  135.             currentFrame = -1*(round(l) + round(h/step));
  136.             if (currentFrame < 0)
  137.                 currentFrame += maxFrame;
  138.             if (currentFrame >= maxFrame)
  139.                 currentFrame -= maxFrame;
  140.             return self;
  141.         }
  142.     }
  143.     oldGridOn = GridOn;
  144.     maxFrame = (360/step);
  145.     currentParams = *params;
  146.     stepValue = step;
  147.     currentFrame = 0;
  148.     [alertWindow makeKeyAndOrderFront:self];
  149.     
  150.     for(i = 0;(i<maxFrame);i++) {
  151.         sprintf(outstr,"Frame %d of %d.",(i+1),maxFrame);
  152.         [alertText setStringValue:outstr];
  153.         newPointList(&outputPoints);
  154.         convertPoints(pts,&outputPoints,GridOn,params);
  155.         params->lon0 = params->lon0+((step/180)*PI);
  156.         if (!(outputFrames[i])) {
  157.             outputFrames[i] = [Bitmap newSize:frame.size.width :frame.size.height
  158.                                 type:NX_UNIQUEBITMAP];
  159.             [outputFrames[i] setFlip:NO];
  160.         }
  161.         [outputFrames[i] lockFocus];
  162.         PSscale((frame.size.width)/(ORight-OLeft),(frame.size.height)/(OTop-OBottom));
  163.         PStranslate(ORight,OTop);
  164.         NXEraseRect(&bounds);
  165.         doMapping(&outputPoints);
  166.         [outputFrames[i] unlockFocus];
  167.         freePointList(&outputPoints);
  168.     }
  169.     [alertText setStringValue:" "];
  170.     [alertWindow close];
  171.     return self;
  172. }
  173.  
  174. - (int)animation
  175. {
  176.     return animating;
  177. }
  178.  
  179. - stopAnimating:(float *)angle;
  180. {
  181.     if (animnum)
  182.         DPSRemoveTimedEntry(animnum);
  183.     animnum = 0;
  184.     animating = STOPPED;
  185.     *angle = (currentFrame*stepValue) + ((currentParams.lon0*180)/PI);
  186.     return self;
  187. }
  188.  
  189. - startAnimating:(int)amate
  190. {
  191.     animnum = DPSAddTimedEntry(rate,(DPSTimedEntryProc)handlerfunction,NULL,NX_BASETHRESHOLD);
  192.     animating = amate;
  193.     return self;
  194. }
  195.  
  196. - rateChanged:(float)f
  197. {
  198.     rate = f;
  199.     if (animnum) {
  200.         DPSRemoveTimedEntry(animnum);
  201.         animnum = DPSAddTimedEntry(rate,(DPSTimedEntryProc)handlerfunction,NULL,NX_BASETHRESHOLD);
  202.     }
  203.     return self;
  204. }
  205.  
  206. - (BOOL)shouldRunPrintPanel:sender
  207. {
  208.     return YES;
  209. }
  210.  
  211. - doPrint:(ProjParam *)params :(PointList *)pts
  212. {
  213.     int holder;
  214.     
  215.     holder = animating;
  216.     animating = STOPPED;
  217.     newPointList(&stillPoints);
  218.     convertPoints(pts,&stillPoints,GridOn,params);
  219.     [self  printPSCode:self];
  220.     freePointList(&stillPoints);
  221.     animating = holder;
  222.     return self;
  223. }
  224.  
  225.  
  226. @end
  227.